Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Run grit migration: Apply a GritQL pattern #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grit-app[bot]
Copy link

@grit-app grit-app bot commented Mar 15, 2024

✅ This migration is up to date! ✅

⚠️ This pull request was auto-generated with Grit. ⚠️

This pull request was created with these settings:

  • Target branch: main
  • Source files: **/*
  • Preset pattern: _convert_default_exports – Replaces export default $something with export const $name = $something. The chosen name matches the file name.
Pattern body
language js

function make_identifiable($original) js {
    return $original.text.replaceAll("-", "_");
}

function guess_name() {
    $original = current_filename_without_extension(),
    $identifiable = make_identifiable($original),
    return $identifiable
}


pattern convert_default_exports($export_name) {
  `export default $export` as $full_export where {
      $guess_name = guess_name(),
      $export_name = $guess_name,
      $export <: or {
          or {
              `async function $name() { $_ }` where { !$name <: ., $export_name = $name },
              `function $name() { $_ }` where { !$name <: ., $export_name = $name },
              `function* $name() { $_ }` where { !$name <: ., $export_name = $name },
              `class $name { $_ }` where { !$name <: ., $export_name = $name },
              `async function($params) { $body }` => `async function $guess_name($params) { $body }`,
              `function($params) { $body }` => `function $guess_name($params) { $body }`,
              `function* ($params) { $body }` => `function* $guess_name($params) { $body }`,
              `class { $body }` where {
                $class_name = capitalize($guess_name)
              } => `class $class_name { $body }`
          } where {
              $full_export => `export $export`
          },
          // handle expression statements
          `$_` where {
              $full_export => `export const $guess_name = $export;`
          }
      }
  }
}

convert_default_exports()

<!-- grit:execution_id:d2c15d7b-9f9d-4652-9cdd-678e10726d2c -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants